import Login from "../page/Login/index.jsx";
import Register from "../page/Register/index.jsx";
import Dashboard from "../page/Dashboard/index.jsx";
import {createBrowserRouter} from "react-router-dom";
import {AuthRoute} from "../components/AuthRoute.jsx";
import Layout from "../page/Layout/index.jsx";
// import Home from "../page/Home/index.jsx";
// import Article from "../page/Article/index.jsx";
// import Publish from "../page/Publish/index.jsx";
import {lazy, Suspense} from "react";

// 路由懒加载
const Home = lazy(() => import("../page/Home/index.jsx"))
const Article = lazy(() => import("../page/Article/index.jsx"))
const Publish = lazy(() => import("../page/Publish/index.jsx"))

const router = createBrowserRouter([
    {
        path : "/login",
        element : <Login/>
    },
    {
        path : "/register",
        element : <Register/>
    },
    {
        path : "/dashboard",
        element : <AuthRoute><Dashboard/></AuthRoute>
    },
    {
        path : "/layout",
        element : <AuthRoute><Layout/></AuthRoute>,
        children : [
            {
                path : "home",
                element : <Suspense fallback={<div>加载中...</div>}><Home/></Suspense>
            },
            {
                path : "article",
                element : <Suspense fallback={<div>加载中...</div>}><Article/></Suspense>
            },
            {
                path : "publish",
                element : <Suspense fallback={<div>加载中...</div>}><Publish/></Suspense>
            }
        ]
    }

])

export {router};